import java.util.*;

public class Solution {
    public ArrayList<Integer> maxInWindows(int[] num, int size) {
        Queue<Integer> queue = new PriorityQueue<>((o1, o2) -> o2 - o1);
        ArrayList<Integer> res = new ArrayList<>();
        if (num == null || num.length == 0 || size <= 0 || size > num.length) {
            return res;
        }
        for (int i = 0; i < num.length; i++) {
            queue.add(num[i]);
            if (queue.size() == size) {
                // System.out.println(queue);
                res.add(queue.peek());
                queue.remove(num[i - size + 1]);
            }
        }
        return res;
    }

    public static void main(String[] args) {
        int[] arr = {2, 3, 4, 2, 6, 2, 5, 1};
        ArrayList<Integer> res = new Solution().maxInWindows(arr, 3);
        System.out.println(res);
    }
}